import 'package:intl/intl.dart';

///本地化数字、货币格式
///
///根据语言环境，格式化数字、货币，返回字符串。
///```
///pattern: "\u00A4 #,###.0#"
/// 0 A single digit
/// # A single digit, omitted if the value is zero
/// . Decimal separator
/// - Minus sign
/// , Grouping separator
/// E Separates mantissa and expontent
/// + - Before an exponent, to say it should be prefixed with a plus sign.
/// % - In prefix or suffix, multiply by 100 and show as percentage
/// ‰ (\u2030) In prefix or suffix, multiply by 1000 and show as per mille
/// ¤ (\u00A4) Currency sign, replaced by currency name
/// ' Used to quote special characters
/// ; Used to separate the positive and negative patterns (if both present)
///```
String NumberFormatter(
    {required dynamic number,
    String pattern = "#,###.##",
    String? locale = "zh_CN"}) {
  return NumberFormat(pattern, locale).format(number);
}

///日期时间格式化
///
///```
///patterns:
///     Symbol   Meaning                Presentation       Example
///     ------   -------                ------------       -------
///     G        era designator(公历纪元标志)(Text)         AD
///     y        year                   (Number)           1996
///     M        month in year          (Text & Number)    July & 07
///     L        standalone month       (Text & Number)    July & 07
///     d        day in month           (Number)           10
///     c        standalone day         (Number)           10
///     h        hour in am/pm (1~12)   (Number)           12
///     H        hour in day (0~23)     (Number)           0
///     m        minute in hour         (Number)           30
///     s        second in minute       (Number)           55
///     S        fractional second      (Number)           978
///     E        day of week            (Text)             Tuesday
///     D        day in year            (Number)           189
///     a        am/pm marker           (Text)             PM
///     k        hour in day (1~24)     (Number)           24
///     K        hour in am/pm (0~11)   (Number)           0
///     Q        quarter                (Text)             Q3
///     '        escape for text        (Delimiter)        'Date='
///     ''       single quote           (Literal)          'o''clock'
/// ```
String DateTimeFormatter({required DateTime dateTime, String? pattern}) {
  pattern ??= 'yyyy-MM-dd';
  return DateFormat(pattern).format(dateTime);
}
